<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <link rel="stylesheet" href="./css/bootstrap/dist/css/bootstrap.css">
    <script src="./js/jquery.js"></script>
    <script src="./js/bootstrap.js"></script>
    <title>课程作业系统</title>
</head>
<body>
<div>
    <%--  未登录  --%>
    <c:if test="${empty user}">
        <%
            response.sendRedirect(request.getContextPath() + "/login.jsp");
        %>
    </c:if>

    <%--  已经登陆  --%>
    <c:if test="${!empty user}">
        <div class="container">
            <nav class="navbar navbar-default">
                <div class="container-fluid">
                    <div class="navbar-header">
                        <button type="button" class="navbar-toggle collapsed" data-toggle="collapse"
                                data-target="#bs-example-navbar-collapse-1" aria-expanded="false">
                            <span class="sr-only">Toggle navigation</span>
                            <span class="icon-bar"></span>
                            <span class="icon-bar"></span>
                            <span class="icon-bar"></span>
                        </button>
                        <a class="navbar-brand" href="#">${user.type}</a>
                    </div>

                    <div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
                        <ul class="nav navbar-nav">
                            <li class="active"><a href="#">主页</a></li>
                            <!-- 教师 -->
                            <c:if test="${user.type == \"TEACHER\"}">
                                <li><a href="${pageContext.request.contextPath}/add.jsp">添加作业</a></li>
                            </c:if>
                            <!-- 学生 -->
                            <c:if test="${user.type == \"STUDENT\"}">
                                <li><a href="#"></a></li>
                            </c:if>
                        </ul>

                        <ul class="nav navbar-nav navbar-right">
                            <li class="dropdown">
                                <a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button"
                                   aria-haspopup="true" aria-expanded="false">${user.name}<span
                                        class="caret"></span></a>
                                <ul class="dropdown-menu">
                                    <li><a href="#">个人中心</a></li>
                                    <li role="separator" class="divider"></li>
                                    <li><a href="${pageContext.request.contextPath}/logoutServlet">退出</a></li>
                                </ul>
                            </li>
                        </ul>
                    </div>
                </div>
            </nav>

            <!-- 我是分割线QAQ -->
            <hr style="border: 1px solid #ddd;">

            <!-- main -->
            <div class="main ">
                <table class="table table-hover table-striped" style="text-align: center;">
                    <thead>
                    <tr>
                        <th style="text-align: center;">序号</th>
                        <th style="text-align: center;">作业名称</th>
                        <th style="text-align: center;">创建时间</th>
                        <th style="text-align: center;">最晚提交时间</th>
                        <th style="text-align: center;">操作</th>
                    </tr>
                    </thead>
                    <tbody>
                    <c:forEach items="${tasks}" var="task" varStatus="i">
                        <tr>
                            <td>${task.id}</td>
                            <td>${task.name}</td>
                            <td>${task.stime}</td>
                            <td>${task.etime}</td>
                            <!-- 教师操作 -->
                            <c:if test="${user.type == \"TEACHER\"}">
                                <td>
                                    <div class="btn-group">
                                        <a
                                            href="${pageContext.request.contextPath}/correctionServlet?task_id=${task.id}"
                                            type="button"
                                            class="btn btn-warning"
                                        >详情</a>
                                    </div>
                                </td>
                            </c:if>
                            <!-- 学生只有详情按钮 -->
                            <c:if test="${user.type == \"STUDENT\"}">
                                <td>
                                    <div class="btn-group">
                                        <a href="${pageContext.request.contextPath}/detailServlet?task_id=${task.id}"
                                           type="button" class="btn btn-warning">详情</a>
                                    </div>
                                </td>
                            </c:if>
                        </tr>
                    </c:forEach>
                    </tbody>
                </table>
            </div>
        </div>
    </c:if>
</div>
</body>
</html>
